<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
//密码重置记录表
class CreatePasswordResetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('password_resets')) { //如果不存在则建表
            Schema::create('password_resets', function (Blueprint $table) {
                $this->create_table($table);
            });
        } else { //否则增量添加字段
            Schema::table('password_resets', function (Blueprint $table) {
                $this->create_table($table);
            });
        }
        DB::statement("alter table `password_resets` comment'密码重置记录表表'");
    }
    public function create_table($table)
    {
        $table->engine = 'InnoDB';
        if (!Schema::hasColumn('password_resets', 'email')) {
            $table->string('email')->index();
        }
        if (!Schema::hasColumn('password_resets', 'token')) {
            $table->string('token');
        }
        if (!Schema::hasColumn('password_resets', 'created_at')) {
            $table->timestamp('created_at')->nullable();
        }
        
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        // Schema::dropIfExists('password_resets');
    }
}
